//
//  PopoverViewController.swift
//  MyWeiboApp
//
//  Created by 胡海波 on 15/7/1.
//  Copyright © 2015年 胡海波. All rights reserved.
//

import UIKit

class PopoverViewController: UIPresentationController {

    var presentedFrame = CGRectZero
    lazy var dummyView: UIView = {

        let v = UIView()

        v.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
        let tap = UITapGestureRecognizer(target: self, action: "close")
        v.addGestureRecognizer(tap)
        return v
    }()

    func close() {

        presentedViewController.dismissViewControllerAnimated(true, completion: nil)
    }


///  容器视图将要重新布局子视图
    override func containerViewWillLayoutSubviews() {

        super.containerViewWillLayoutSubviews()

        // 添加并且设置 dummyView
        dummyView.frame = containerView!.bounds
        containerView?.insertSubview(dummyView, atIndex: 0)

        // 设置视图大小
        presentedView()?.frame = presentedFrame
    }
}
